package com.syt.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.syt.commonutils.R;
import com.syt.eduservice.entity.EduCourse;
import com.syt.eduservice.entity.EduTeacher;
import com.syt.eduservice.service.EduCourseService;
import com.syt.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

//@CrossOrigin
@RestController
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {

    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduTeacherService teacherService;
    //查询前八条热门课程,查询前4条名师
    @GetMapping("index")
    public R index(){
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.orderByDesc("id").last("limit 8");
        List<EduCourse> courseList = courseService.list(wrapper);

        QueryWrapper<EduTeacher> wrapper2=new QueryWrapper<>();
        wrapper2.orderByDesc("id").last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(wrapper2);
        return R.ok().data("eduList",courseList).data("teacherList",teacherList);
    }
}
